#include "widget.h"
#include <QString>
#include <QDebug>
#include <QPushButton>
#include "newwin.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
{
    this->setWindowTitle("窗口1");
        //设置窗口名称
    QString s = windowTitle();
    qDebug()<<s;
        //qDebug会自动换行
    this->resize(800,600);
        //设置窗口大小
    this->setFixedSize(800,600);
        //设置固定大小
    QPushButton *mynewbutton = new QPushButton;
    mynewbutton->setParent(this);
    mynewbutton->setText("按钮一");
    mynewbutton->resize(100,50);
    mynewbutton->move(50,500);
    connect(mynewbutton,&QPushButton::clicked,this,myfunc);
        //connect(信号的发起者按钮,信号事件按钮事件,信号接收方，槽函数命)
        //报错不用管

        //用户自定义的槽函数，要在下面定义void Widget::myfunc(){}
        //在widget.h 声明为槽函数public slots: void myfunc();

    QPushButton *mynewbutton2 = new QPushButton;
    mynewbutton2->setParent(this);
    mynewbutton2->setText("按钮二");
    mynewbutton2->resize(100,50);
    mynewbutton2->move(250,500);
    connect(mynewbutton2,&QPushButton::clicked,this,QWidget::close);
        //widget自带的槽函数，关闭窗口

    QPushButton *mynewbutton3 = new QPushButton;
    mynewbutton3->setParent(this);
    mynewbutton3->setText("按钮三");
    mynewbutton3->resize(100,50);
    mynewbutton3->move(450,500);
    connect(mynewbutton3, &QPushButton::clicked, this, [=](){
        qDebug()<< "按钮3点击了";
    });
        //使用lambda表达式实现槽函数
    QPushButton *mynewbutton4 = new QPushButton;
    mynewbutton4->setParent(this);
    mynewbutton4->setText("按钮四");
    mynewbutton4->resize(100,50);
    mynewbutton4->move(650,500);

    NewWin *mynewwin = new NewWin;
    connect(mynewbutton4, &QPushButton::clicked, [=](){
        this->hide();
        //隐藏窗口一
        mynewwin->show();
        //开启窗口二
    });
        //实现单击按钮切换到页面二

    connect(mynewwin, &NewWin::mysignal2, [=](int val){
        //带参数的信号
        mynewwin->hide();
        this->show();
        //接收到信号，处理该信号
        //将窗口二隐藏，窗口一显示
    });

}

Widget::~Widget()
{
}

void Widget::myfunc()
{
    qDebug()<<"点击了1";
}

